public class ThreadDemo7 {
    public static void main(String[] args) {

        //创建一个线程，使用isInterrupted进行判断
        //每执行一次后进行sleep一秒的时间
        Thread thread = new Thread(() -> {
            while(!Thread.currentThread().isInterrupted()) {
                System.out.println("hello t");
                //System.out.println(Thread.currentThread().isInterrupted());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    //break;
                }
            }
        });
        //在main线程中调用该线程
        thread.start();

        //让main线程sleep三秒钟后使用Thread自带的标志位interrupt来将其设置为中断线程
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

//        for (int i = 0; i < 5; i++) {
//          thread.interrupt();
//        }
        thread.interrupt();
        //System.out.println(thread.isInterrupted());
    }
}
